package com.tonann.app.controller;

import com.tonann.app.domain.AppEnergyCaculatedRule;
import com.tonann.app.service.IAppEnergyCaculatedRuleService;
import com.tonann.common.annotation.Log;
import com.tonann.common.core.controller.BaseController;
import com.tonann.common.core.domain.AjaxResult;
import com.tonann.common.core.page.TableDataInfo;
import com.tonann.common.enums.BusinessType;
import com.tonann.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 运算规则Controller
 *
 * @author tonann
 * @date 2022-10-21
 */
@RestController
@RequestMapping("/app/energyCaculatedRule")
public class AppEnergyCaculatedRuleController extends BaseController {
    @Autowired
    private IAppEnergyCaculatedRuleService appEnergyCaculatedRuleService;

    /**
     * 查询运算规则列表
     */
    @PreAuthorize("@ss.hasPermi('app:energyCaculatedRule:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppEnergyCaculatedRule appEnergyCaculatedRule) {
        startPage();
        List<AppEnergyCaculatedRule> list = appEnergyCaculatedRuleService.selectAppEnergyCaculatedRuleList(appEnergyCaculatedRule);
        return getDataTable(list);
    }

    /**
     * 导出运算规则列表
     */
    @PreAuthorize("@ss.hasPermi('app:energyCaculatedRule:export')")
    @Log(title = "运算规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppEnergyCaculatedRule appEnergyCaculatedRule) {
        List<AppEnergyCaculatedRule> list = appEnergyCaculatedRuleService.selectAppEnergyCaculatedRuleList(appEnergyCaculatedRule);
        ExcelUtil<AppEnergyCaculatedRule> util = new ExcelUtil<AppEnergyCaculatedRule>(AppEnergyCaculatedRule.class);
        util.exportExcel(response, list, "运算规则数据");
    }

    /**
     * 获取运算规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:energyCaculatedRule:query')")
    @GetMapping(value = "/{ruleId}")
    public AjaxResult getInfo(@PathVariable("ruleId") Long ruleId) {
        return AjaxResult.success(appEnergyCaculatedRuleService.selectAppEnergyCaculatedRuleByRuleId(ruleId));
    }

    /**
     * 新增运算规则
     */
    @PreAuthorize("@ss.hasPermi('app:energyCaculatedRule:add')")
    @Log(title = "运算规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppEnergyCaculatedRule appEnergyCaculatedRule) {
        return toAjax(appEnergyCaculatedRuleService.insertAppEnergyCaculatedRule(appEnergyCaculatedRule));
    }

    /**
     * 修改运算规则
     */
    @PreAuthorize("@ss.hasPermi('app:energyCaculatedRule:edit')")
    @Log(title = "运算规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppEnergyCaculatedRule appEnergyCaculatedRule) {
        return toAjax(appEnergyCaculatedRuleService.updateAppEnergyCaculatedRule(appEnergyCaculatedRule));
    }

    /**
     * 删除运算规则
     */
    @PreAuthorize("@ss.hasPermi('app:energyCaculatedRule:remove')")
    @Log(title = "运算规则", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ruleIds}")
    public AjaxResult remove(@PathVariable Long[] ruleIds) {
        return toAjax(appEnergyCaculatedRuleService.deleteAppEnergyCaculatedRuleByRuleIds(ruleIds));
    }
}
